package org.dormi.learn.definition;

import java.util.Objects;

/**
 * @author : dormi330
 * @since : 2021/1/27/0027
 * 边
 */
public class Edge {
    public final Vertex v1;
    public final Vertex v2;

    public Edge(Vertex v1, Vertex v2) {
        this.v1 = v1;
        this.v2 = v2;
    }

    @Override
    public String toString() {
        return String.format("[%s -> %s]", v1.uid, v2.uid);
    }

    @Override
    public int hashCode() {
        return v1.uid.hashCode() + v2.uid.hashCode();
    }

    @Override
    public boolean equals(Object other) {
        if (other == null) {
            return false;
        }
        if (!(other instanceof Edge)) {
            return false;
        }

        Edge e2 = (Edge) other;
        if (Objects.equals(v1, e2.v1) && Objects.equals(v2, e2.v2)) {
            return true;
        }

        return false;
    }

}
